<template>
	<div>
		<el-form ref="form" :model="form" :rules="rules" label-width="80px">

			<el-row>
				<el-col span="10">
					<el-form-item label="姓名" prop="customerName">
						<el-input v-model="form.customerName"></el-input>
					</el-form-item>
				</el-col>
				<el-col span="10">
					<el-form-item label="性别" prop="customerGender" label-width="150px">
						<el-select v-model="form.customerGender" placeholder="请选择..">
							<el-option v-for="item in options" :key="item.value" :label="item.label"
								:value="item.value">
							</el-option>
						</el-select>
					</el-form-item>
				</el-col>
			</el-row>

			<el-row>
				<el-col span="10">
					<el-form-item label="年龄" prop="customerAge">
						<el-input v-model="form.customerAge"></el-input>
					</el-form-item>
				</el-col>
				<el-col span="10">
					<el-form-item label="健康卡号/身份证号" prop="idNumber" label-width="150px">
						<el-input v-model="form.idNumber"></el-input>
					</el-form-item>
				</el-col>
			</el-row>

			<el-row>
				<el-col span="10">
					<el-form-item label="房间号">
						<el-input v-model="form.roomId"></el-input>
					</el-form-item>

				</el-col>
				<el-col span="10">
					<el-form-item label="所属楼房" label-width="150px">
						<el-input v-model="form.house"></el-input>
					</el-form-item>
				</el-col>
			</el-row>

			<el-row>
				<el-col span="10">
					<el-form-item label="入住时间" prop="checkinDate">
						<el-date-picker value-format="yyyy-MM-dd" type="date" v-model="form.checkinDate"
							placeholder="选择日期">
						</el-date-picker>
					</el-form-item>

				</el-col>
				<el-col span="10">
					<el-form-item label="合同到期时间" prop="expireDate" label-width="150px">
						<el-date-picker value-format="yyyy-MM-dd" type="date" v-model="form.expireDate"
							placeholder="选择日期">
						</el-date-picker>
					</el-form-item>
				</el-col>
			</el-row>

			<el-row>
				<el-col span="10">
					<el-form-item label="档案编号" prop="recordId">
						<el-input v-model="form.recordId"></el-input>
					</el-form-item>
				</el-col>
				<el-col span="10">
					<el-form-item label="联系电话" prop="telephone" label-width="150px">
						<el-input v-model="form.telephone"></el-input>
					</el-form-item>
				</el-col>
			</el-row>

			<el-row>
				<el-col span="10">
					<el-form-item label="家属" prop="families">
						<el-input v-model="form.families"></el-input>
					</el-form-item>
				</el-col>
				<el-col span="10">
					<el-form-item label="陪住人" label-width="150px">
						<el-input v-model="form.accompaniedPerson"></el-input>
					</el-form-item>
				</el-col>
			</el-row>

			<el-row>
				<el-col span="10">
					<el-form-item label="评估医生" prop="assessDoctor">
						<el-input v-model="form.assessDoctor"></el-input>
					</el-form-item>
				</el-col>
				<el-col span="10">
					<el-form-item label="责任医生" prop="respDoctor" label-width="150px">
						<el-input v-model="form.respDoctor"></el-input>
					</el-form-item>

				</el-col>
			</el-row>

			<el-row>
				<el-col span="10">
					<el-form-item label="护工" prop="carer">
						<el-input v-model="form.carer"></el-input>
					</el-form-item>
				</el-col>
				<el-col span="10">
					<el-form-item label="健康管家" prop="healthPerson" label-width="150px">
						<el-input v-model="form.healthPerson"></el-input>
					</el-form-item>
				</el-col>
			</el-row>

			<el-row>
				<el-col>
					<el-form-item label="备注">
						<el-input v-model="form.remarks"></el-input>
					</el-form-item>
				</el-col>
			</el-row>
			<el-row></el-row>
			<el-form-item>
				<el-button type="primary" plain @click="save">保存数据</el-button>
			</el-form-item>
		</el-form>
	</div>
</template>

<script>
	import axios from '@/utils/axiosutils.js';
	export default {
		name: 'CheckinAdd',
		props: ['editid'],
		components: {},
		data() {
			return {
				form: {
					customerName: '',
					customerGender: '',
					customerAge: '',
					idNumber: '',
					roomId: '',
					house: '',
					recordId: '',
					checkinDate: '',
					expireDate: '',
					telephone: '',
					families: '',
					accompaniedPerson: '',
					assessDoctor: '',
					respDoctor: '',
					carer: '',
					healthPerson: '',
					remarks: ''
				},
				rules: {
					customerName: [{
						required: true,
						message: '请输入',
						trigger: 'blur'
					}],
					customerGender: [{
						required: true,
						message: '请输入',
						trigger: 'blur'
					}],
					customerAge: [{
						required: true,
						message: '请输入',
						trigger: 'blur'
					}],
					idNumber: [{
						required: true,
						message: '请输入',
						trigger: 'blur'
					}],
					recordId: [{
						required: true,
						message: '请输入',
						trigger: 'blur'
					}],
					checkinDate: [{
						required: true,
						message: '请输入',
						trigger: 'blur'
					}],
					expireDate: [{
						required: true,
						message: '请输入',
						trigger: 'blur'
					}],
					telephone: [{
						required: true,
						message: '请输入',
						trigger: 'blur'
					}],
					families: [{
						required: true,
						message: '请输入',
						trigger: 'blur'
					}],
					assessDoctor: [{
						required: true,
						message: '请输入',
						trigger: 'blur'
					}],
					respDoctor: [{
						required: true,
						message: '请输入',
						trigger: 'blur'
					}],
					carer: [{
						required: true,
						message: '请输入',
						trigger: 'blur'
					}],
					healthPerson: [{
						required: true,
						message: '请输入',
						trigger: 'blur'
					}]
				},
				isupdate: false,
				options: [{
					value: '男',
					label: '男'
				}, {
					value: '女',
					label: '女'
				}]
			};
		},
		created() {
			if (this.editid) {
				// 如果是修改 用户名输入框禁用
				this.isupdate = true;
				axios.get(
					'/checkin/getById',
					response => {
						this.form.checkinId = this.editid;
						this.form.customerName = response.obj.customerName;
						this.form.customerGender = response.obj.customerGender;
						this.form.customerAge = response.obj.customerAge;
						this.form.idNumber = response.obj.idNumber;
						this.form.roomId = response.obj.roomId;
						this.form.house = response.obj.house;
						this.form.recordId = response.obj.recordId;
						this.form.checkinDate = response.obj.checkinDate;
						this.form.expireDate = response.obj.expireDate;
						this.form.telephone = response.obj.telephone;
						this.form.families = response.obj.families;
						this.form.accompaniedPerson = response.obj.accompaniedPerson;
						this.form.assessDoctor = response.obj.assessDoctor;
						this.form.respDoctor = response.obj.respDoctor;
						this.form.carer = response.obj.carer;
						this.form.healthPerson = response.obj.healthPerson;
						this.form.remarks = response.obj.remarks;
					}, {
						checkinId: this.editid
					}
				);
			}
		},
		methods: {
			save: function() {
				if (this.editid) {
					axios.post(
						'/checkin/update',
						resp => {
							this.$emit('update:show', false);
							this.$emit('getData');
						},
						this.form
					);
				} else {
					axios.post(
						'/checkin/add',
						resp => {
							this.$emit('update:show', false);
							this.$emit('getData');
						},
						this.form
					);
					axios.post(
						'/bed/save',
						resp=>{
							
						},
							this.form
						
						
					)
				}
			}
		}
	}
</script>

<style scoped>
	.el-row{
		height: 60px;
	}
	
</style>
